<?php
html::printPath(array(
		'seminar.form-title' => 'admin/seminar/all',
		$this->data->seminar['name'] => '/admin/seminar/display?id=' . $this->data->seminar['id'],
		'seminarAccounts.form-title' => '/admin/seminarAccounts/selectOrganizationForm?id=' . $this->data->seminar['id'],
		$this->data->organization['name'] => ''
		)
);
$msg->printMessages();

if (! $paymentAcceptance['confirmed_at']) {
	html::actionLists(array(
			'closeAction' => html::popup('/admin/seminarAccounts/confirmForm', text::get('seminarAccounts-lockOrganization')) . ' - ' . text::get('seminarAccounts-lockOrganization-desc')
	));
}

// Payment vs price difference
echo '<ul>';
if ($paymentAcceptance['confirmed_at']) {
	echo '<li class="locked">' . text::getEscaped('seminarAccounts-accountingConfirmed') . '</li>';
}
if (! $paymentsMinusPricesByCurrency) {
	echo '<li class="correctItem">' . text::getEscaped('seminarAccounts-billingIsOK') . '</li>';
}
else {
	foreach ($paymentsMinusPricesByCurrency as $currencyCode => $value) {
		$diffType = 'payedLess';
		if ($value > 0) {
			$diffType = 'payedMore';
		}
		echo '<li class="incorrectItem"><span style="color: red; font-weight: bold">' . text::getEscaped('seminarAccounts-' . $diffType) . '</span>: <span class="registrationPrice">' . format::price(abs($value), $currencyCode) . '</span></li>';
	}
}
echo '</ul>';

if ($paymentAcceptance['confirmed_at']) {
	$confirmationInfo = array(
			text::get('paymentAcceptance-confirmed_at') => format::timestamp($paymentAcceptance['confirmed_at']),
			text::get('paymentAcceptance-confirmed_by_id') => format::personFullName($paymentAcceptance['confirmed_by']),
	);
	if ($paymentAcceptance['confirmation_notes']) {
		$confirmationInfo[text::get('paymentAcceptance-confirmation_notes')] = $paymentAcceptance['confirmation_notes'];
	}
	html::displayTable($confirmationInfo);
}

echo '<h3>' . text::getEscaped('seminarAccounts-totalPrice') . '</h3>';

echo html::displayTable(array(
		text::get('orgSeminar-billing-total') => registrationHelper::formatPrices($totalPriceByCurrency),
		text::get('orgSeminar-billing-cancellationFees') => registrationHelper::formatPrices($cancellationFeesByCurrency)
), false);

echo '<h3>' . text::getEscaped('seminarAccounts-orgPaymentList') . '</h3>';

if (! $paymentAcceptance['confirmed_at']) { ?>
	<ul class="commandList">
	    <li class="addLi"><?php echo html::popup('admin/seminarOrgPayment/edit?seminar_id=' . $this->data->seminar['id'] . '&organization_id=' . $this->data->organization['id'] . '&fromAccounts=true', text::get('seminarOrgPayment-createNew')) ?></li>
	</ul>
	<?php
}

if ($paymentList) {
	$elb = new EntityListBuilder('seminarOrgPayment', $paymentList, 'id');
	$elb->integer('id')->linkWithValue('admin/seminarOrgPayment/display?id=')->openInPopup();
	$elb->text('payment_identification');
	$elb->price('amount', 'currency_code')->alignRight();
	$elb->date('received_on');
	$elb->longText('notes');
	$elb->write();
	
	echo html::displayTable(array(
			text::get('seminarOrgPayment-total') => registrationHelper::formatPrices($totalPaymentsByCurrency)
	), false);
}
else {
	echo '<p>' . text::getEscaped('seminarAccounts-orgPaymentList-noRecord') . '</p>';
}

echo '<h2>' . text::getEscaped('seminarAccounts-registrationList') . '</h2>';

echo '<h3>' . text::getEscaped('seminarAccounts-validRegistrationList') . ' (' . count($registrationList) . ')</h3>';
echo '<p class="description">' . text::getEscaped('seminarAccounts-validRegistrationList-info') . '</p>';

if ($registrationList) {
	$elb = new EntityListBuilder('registration', $registrationList);
	$elb->setUuid($this->REGISTRATION_LIST_UUID);
	$elb->integer('id')->linkWithValue('/admin/registration/display?id=', 'id')->openInPopup();
	$elb->text('person_id')->doubleValue('last_name', 'first_name')->alignLeft()->orderByField('last_name')->linkWithValue('/admin/person/display?id=', 'person_id');
	$elb->timestamp('created_at');
	$elb->text('payment_type')->l10n('registration.paymentType-');
	$elb->price('total_price', 'currency_code')->alignRight();
	$elb->price('price_paid', 'currency_code')->valueFunction('registrationHelper::pricePaidValue')->alignRight();
	$elb->timestamp('confirmed_at');
	$elb->text('confirmed_by_last_name')->labelKey('registration.confirmed_by_id')->doubleValue('confirmed_by_first_name', 'confirmed_by_last_name');
	$elb->longText('org_notes');
	echo '<div class="registrationList-valid">';
	$elb->write();
	echo '</div>';
}
else {
	echo text::getEscaped('seminarAccounts-noValidRegistration');
}

echo '<h3>' . text::getEscaped('seminarAccounts-unconfirmedRegistrationList') . ' (' . count($unconfirmedRegistrationList) . ')</h3>';
echo '<p class="description">' . text::getEscaped('seminarAccounts-unconfirmedRegistrationList-info') . '</p>';
if ($unconfirmedRegistrationList) {
	$elb = new EntityListBuilder('registration', $unconfirmedRegistrationList);
	$elb->setUuid($this->UNCONFIRMED_REGISTRATION_LIST_UUID);
	$elb->integer('id')->linkWithValue('/admin/registration/display?id=', 'id')->openInPopup();
	$elb->text('person_id')->doubleValue('last_name', 'first_name')->alignLeft()->orderByField('last_name')->linkWithValue('/admin/person/display?id=', 'person_id');
	$elb->timestamp('created_at');
	$elb->text('payment_type')->l10n('registration.paymentType-');
	$elb->price('total_price', 'currency_code')->alignRight();
	$elb->longText('org_notes');
	echo '<div class="registrationList-unconfirmed">';
	$elb->write();
	echo '</div>';
}

echo '<h3>' . text::getEscaped('seminarAccounts-cancelledRegistrationList') . ' (' . count($cancelledRegistrationList) . ')</h3>';
echo '<p class="description">' . text::getEscaped('seminarAccounts-cancelledRegistrationList-info') . '</p>';
if ($cancelledRegistrationList) {
	$elb = new EntityListBuilder('registration', $cancelledRegistrationList);
	$elb->setUuid($this->REGISTRATION_LIST_UUID);
	$elb->integer('id')->linkWithValue('/admin/registration/display?id=', 'id')->openInPopup();
	$elb->text('person_id')->doubleValue('last_name', 'first_name')->alignLeft()->orderByField('last_name')->linkWithValue('/admin/person/display?id=', 'person_id');
	$elb->timestamp('created_at');
	$elb->text('payment_type')->l10n('registration.paymentType-short-');
	$elb->price('total_price', 'currency_code')->alignRight();
	$elb->price('price_paid', 'currency_code')->valueFunction('registrationHelper::pricePaidValue')->alignRight();
	$elb->timestamp('cancelled_at');
	$elb->text('cancelled_by_id')->doubleValue('cancelled_by_last_name', 'cancelled_by_first_name')->alignLeft()->orderByField('cancelled_by_last_name')->linkWithValue('/org/orgSpace/personDisplay?id=', 'cancelled_by_id');
	$elb->price('cancellation_fee', 'currency_code')->alignRight();
	$elb->longText('cancellation_reason');
	$elb->longText('org_notes');
	echo '<div class="registrationList-cancelled">';
	$elb->write();
	echo '</div>';
}
